<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<div style="width:100%;height:14%;">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
																<span>设备名称：</span>
								<input name="deviceName" class="mini-textbox" style="width: 150px" />
								<input name="deviceName_link" value="=" class="mini-hidden" style="width: 150px" />
								<a class="mini-button" onclick="doSearch">查询</a>
								<a class="mini-button" onclick="doAdd">新增</a>
								<a class="mini-button" onclick="doEdit">修改</a>
								<a class="mini-button" onclick="doSave">保存</a>
								<a class="mini-button" onclick="doDelete">删除</a>
								<a class="mini-button mini-button-primary" id="seniorSearchWindow" onclick="openSeniorSearchWindow()">高级查询</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

		</div>
		<div style="width:100%;height:86%;">
			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" idField="instID" allowResize="true">
				</div>
			</div>
		</div>

		<div id="seniorSearchWindow" class="mini-window" title="" style="width:550px;height:400px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true"
		 showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div class="mini-fit">
				<div id="seniorSearchGrid" class="mini-datagrid" style="width:100%;height:100%;" showPager="false" allowCellEdit="true" allowCellSelect="true" editNextOnEnterKey="true"
				 editNextRowCell="true">
					<div property="columns">
						<div field="index" type="indexcolumn" width="20"></div>
						<div name="title" field="title" headerAlign="center" width="120">名称
							<input property="editor" class="mini-textbox" style="width:100%;" minWidth="120" />
						</div>
						<div type="comboboxcolumn" autoShowPopup="true" name="comparison" field="comparison" width="50" align="center" headerAlign="center">比较符
							<input property="editor" class="mini-combobox" style="width:100%;" data="CONST.compareTypes" />
						</div>
						<div name="defaultValue" field="defaultValue" headerAlign="center" width="80">值
							<input property="editor" class="mini-textbox" style="width:100%;" minWidth="80" />
						</div>
					</div>
				</div>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button mini-button-primary" onClick="doSeniorSearch()">查询</a>
			</div>
		</div>

		<!-- 计算需要显示的控件数量 -->
		<!-- 根据控件数量计算窗体的高度 -->
		<!-- 主键名称 -->
		<div id="detailWin" class="mini-window" title="" style="width:600px;height:190px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true"
		 showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div id="detailForm" style="padding:10px;">
				<table align="center">
					<input class="mini-hidden" name="deviceID">
						<tr>
							<td align="right">编号：</td>
							<td align="left"><input name="deviceID" class="mini-textbox" ></td>
							<td align="right">设备名称：</td>
							<td align="left"><input name="deviceName" class="mini-textbox" ></td>
						</tr>
						<tr>
							<td align="right">设备IP地址：</td>
							<td align="left"><input name="deviceIp" class="mini-textbox" ></td>
							<td align="right">当前用户数量：</td>
							<td align="left"><input name="userCount" class="mini-textbox" ></td>
						</tr>
						<tr>
							<td align="right">状态：</td>
							<td align="left"><input name="status" class="mini-textbox" ></td>
				<!-- 如果是单数就补充缺失部分 -->
							<td></td>
							<td></td>
						</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" onClick="doSave()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		miniInit();

		var className = "com.business.bean.device.FaceDevice";

		var queryForm = new mini.Form("#queryForm");
		var detailForm = new mini.Form("#detailForm");
		var win = mini.get("detailWin");

		var datagrid = mini.get("datagrid");
		datagrid.set({
			url: http.getUrl("/com/bean/page.do?className=" + className),
			columns: [{
					type: "indexcolumn"
				}
				,{
					field: "deviceID",
					width: 20,
					headerAlign: "center",
					allowSort: true,
					header: "编号"
				}
				,{
					field: "deviceName",
					width: 20,
					headerAlign: "center",
					allowSort: true,
					header: "设备名称"
				}
				,{
					field: "deviceIp",
					width: 20,
					headerAlign: "center",
					allowSort: true,
					header: "设备IP地址"
				}
				,{
					field: "userCount",
					width: 20,
					headerAlign: "center",
					allowSort: true,
					header: "当前用户数量"
				}
				,{
					field: "status",
					width: 20,
					headerAlign: "center",
					allowSort: true,
					header: "状态"
				}
			]
		});
		var orderByString = "";

		// 表单与表格绑定数据
		var db = new mini.DataBinding();
		db.bindForm("detailForm", datagrid);

		doSearch();
		function doSearch() {
			var data = queryForm.getData(true, false);
			if (orderByString != "") {
				data["orderBy"] = orderByString;
			}
			datagrid.load(data, null, miniui.showLoadErrorMessageBox);
		}

		// 新增污染物
		function doAdd() {
			datagrid.clearSelect(false);
			detailForm.reset();
			win.setTitle("新增机构");
			win.showAtPos('center', 'middle');
		}

		// 保存污染物
		function doSave() {
			if(!detailForm.validate()) {
				return;
			}
			mini.mask({
				el: document.body,
				cls: 'mini-mask-loading',
				html: '数据保存中...'
			});
			var data = detailForm.getData(true);
			data.className = className;
			http.post(http.getUrl("/com/bean/save.do"), data, function(page) {
				mini.unmask();
				win.hide();
				mini.alert("保存成功", "提示", null);
				datagrid.reload();
			});
		}

		// 修改污染物
		function doEdit() {
			if(datagrid.getSelected()) {
				win.setTitle("修改机构数据");
				win.showAtPos('center', 'middle');
			} else {
				mini.alert("请选中需要修改的数据行", "提示", null);
			}
		}

		function cancel() {
			win.hide();
		}

		// 删除用户
		function doDelete() {
			if(datagrid.getSelected() == null) {
				mini.alert("请选中需要删除的数据行", "提示", null);
				return;
			}

			mini.confirm("确认删除该数据信息吗？", "删除操作", function(e) {
				if(e == "ok") {
					mini.mask({
						el: document.body,
						cls: 'mini-mask-loading',
						html: '数据删除中...'
					});
					var ids = datagrid.getSelected().deviceID;
					var data = {
						"id": ids
					};
					data.className = className;
					http.post(http.getUrl("/com/bean/delete.do"), data, function(page) {
						mini.unmask();
						win.hide();
						mini.alert("删除成功", "提示", null);
						datagrid.reload();
					});
				}
			});
		}

		/************************************************************************
		 * 高级查询
		 ************************************************************************/
		var seniorSearchWindow = mini.get("seniorSearchWindow");
		var seniorSearchGrid = mini.get("seniorSearchGrid");
		var seniorSearchData = [
		];
		seniorSearchGrid.setData(seniorSearchData);

		function openSeniorSearchWindow() {
			seniorSearchWindow.setTitle("高级查询");
			var atEl = document.getElementById("seniorSearchWindow");
			seniorSearchWindow.showAtEl(atEl, {
				"xAlign": "center",
				"yAlign": "below"
			});
		}

		function doSeniorSearch() {
			var list = seniorSearchGrid.getData();
			var query = {};
			for(var index = 0, len = list.length; index < len; index++) {
				if(list[index].defaultValue && list[index].defaultValue != "") {
					query[list[index].property] = list[index].defaultValue;
					query[list[index].property + "_link"] = list[index].comparison;
					debugger
				}
			}
			if (orderByString!="") {
				query["orderBy"] = orderByString;
			}
			datagrid.load(query, null, miniui.showLoadErrorMessageBox);
			seniorSearchWindow.hide();
		}
	</script>

</html>